GtkSnapshot: Always use int for the translation
authorAlexander Larsson <alexl@redhat.com>
Wed, 11 Jan 2017 15:14:03 +0000 (16:14 +0100)
committerAlexander Larsson <alexl@redhat.com>
Wed, 11 Jan 2017 15:14:03 +0000 (16:14 +0100)
We already take ints when setting the translation, so it can't
currently take any other values. Additionally, I was seeing large
costs in int -> double -> int for the rects in
gtk_snapshot_clips_rect(), as all callers really are ints (widget
allocations) and the clip region is int-based.

This change completely cleared a 2% rectangle_init_from_graphene from
the profile and is likely to have nice performance effects elsewhere
too.

gtk/gtkcssgadget.c
gtk/gtkcssimagelinear.c
gtk/gtkcssshadowvalue.c
gtk/gtkiconview.c
gtk/gtkrenderborder.c
gtk/gtksnapshot.c
gtk/gtksnapshot.h
gtk/gtksnapshotprivate.h
gtk/gtkwidget.c

index 3fb2f0af370969987299926f9416b7bb0c3b9982..f2ee45609fd9d3f80beddb19a216249579608ab9 100644 (file)
@@ -834,7 +834,7 @@ gtk_css_gadget_snapshot (GtkCssGadget *gadget,
 
   clip = priv->clip;
   shift_allocation (gadget, &clip);
-  if (gtk_snapshot_clips_rect (snapshot, &GRAPHENE_RECT_INIT(clip.x, clip.y, clip.width, clip.height)))
+  if (gtk_snapshot_clips_rect (snapshot, &clip))
     return;
 
   gtk_css_gadget_get_margin_box (gadget, &margin_box);
index 592180a0209818e8d30f06bc2b2cbcddcf1b87e1..7200c4895167ce81264beab4ada33711318516f6 100644 (file)
@@ -136,7 +136,7 @@ gtk_css_image_linear_snapshot (GtkCssImage        *image,
   GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
   GskColorStop *stops;
   GskRenderNode *node;
-  double off_x, off_y; /* snapshot offset */
+  int off_x, off_y; /* snapshot offset */
   double angle; /* actual angle of the gradiant line in degrees */
   double x, y; /* coordinates of start point */
   double length; /* distance in pixels for 100% */
index 1be9708159b740633751ae5bb077bca0efe659df..ed565041663b6cb536227306f91783bde344a88b 100644 (file)
@@ -1039,7 +1039,7 @@ gtk_css_shadow_value_snapshot_outset (const GtkCssValue    *shadow,
 {
   GskRoundedRect outline;
   GskRenderNode *node;
-  double off_x, off_y;
+  int off_x, off_y;
 
   g_return_if_fail (shadow->class == &GTK_CSS_VALUE_SHADOW);
 
@@ -1070,7 +1070,7 @@ gtk_css_shadow_value_snapshot_inset (const GtkCssValue   *shadow,
 {
   GskRoundedRect outline;
   GskRenderNode *node;
-  double off_x, off_y;
+  int off_x, off_y;
 
   g_return_if_fail (shadow->class == &GTK_CSS_VALUE_SHADOW);
 
index 6f092fb5397f038bb37a092831b6f7cd0466bcb7..2cbc6802aa7cc086e5fb77057c463e103166e285 100644 (file)
@@ -1783,14 +1783,14 @@ gtk_icon_view_snapshot (GtkWidget   *widget,
   for (icons = icon_view->priv->items; icons; icons = icons->next)
     {
       GtkIconViewItem *item = icons->data;
+      cairo_rectangle_int_t area;
 
-      if (!gtk_snapshot_clips_rect (snapshot,
-                                    &GRAPHENE_RECT_INIT (
-                                        item->cell_area.x      - icon_view->priv->item_padding,
-                                        item->cell_area.y      - icon_view->priv->item_padding,
-                                        item->cell_area.width  + icon_view->priv->item_padding * 2,
-                                        item->cell_area.height + icon_view->priv->item_padding * 2
-                                    )))
+      area.x = item->cell_area.x - icon_view->priv->item_padding;
+      area.y = item->cell_area.y      - icon_view->priv->item_padding;
+      area.width = item->cell_area.width  + icon_view->priv->item_padding * 2;
+      area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
+
+      if (!gtk_snapshot_clips_rect (snapshot, &area))
         {
           gtk_icon_view_snapshot_item (icon_view, snapshot, item,
                                        item->cell_area.x, item->cell_area.y,
index 31f5725efb1d379f742061b5176ade7715571654..a42f74e42bec25e167b11ba294e6ace4b387a34a 100644 (file)
@@ -414,7 +414,7 @@ snapshot_frame_fill (GtkSnapshot          *snapshot,
 {
   GskRoundedRect offset_outline;
   GskRenderNode *node;
-  double off_x, off_y;
+  int off_x, off_y;
 
   if (hidden_side)
     {
index 72f1b1586f832e8d175f7018996857706e9487ad..08db8c5b634da124cda0b173fb42ac66aa828f8b 100644 (file)
@@ -78,8 +78,8 @@ static GtkSnapshotState *
 gtk_snapshot_state_new (GtkSnapshotState       *parent,
                         char                   *name,
                         cairo_region_t         *clip,
-                        double                  translate_x,
-                        double                  translate_y,
+                        int                     translate_x,
+                        int                     translate_y,
                         GtkSnapshotCollectFunc  collect_func)
 {
   GtkSnapshotState *state;
@@ -797,8 +797,8 @@ gtk_snapshot_translate_2d (GtkSnapshot *snapshot,
  **/
 void
 gtk_snapshot_get_offset (GtkSnapshot *snapshot,
-                         double      *x,
-                         double      *y)
+                         int         *x,
+                         int         *y)
 {
   if (x)
     *x = snapshot->state->translate_x;
@@ -996,18 +996,19 @@ gtk_snapshot_append_color_node (GtkSnapshot           *snapshot,
  */
 gboolean
 gtk_snapshot_clips_rect (GtkSnapshot           *snapshot,
-                         const graphene_rect_t *bounds)
+                         const cairo_rectangle_int_t *rect)
 {
-  graphene_rect_t offset_bounds;
-  cairo_rectangle_int_t rect;
+  cairo_rectangle_int_t offset_rect;
 
   if (snapshot->state->clip_region == NULL)
     return FALSE;
 
-  graphene_rect_offset_r (bounds, snapshot->state->translate_x, snapshot->state->translate_y, &offset_bounds);
-  rectangle_init_from_graphene (&rect, &offset_bounds);
+  offset_rect.x = rect->x + snapshot->state->translate_x;
+  offset_rect.y = rect->y + snapshot->state->translate_y;
+  offset_rect.width = rect->width;
+  offset_rect.height = rect->height;
 
-  return cairo_region_contains_rectangle (snapshot->state->clip_region, &rect) == CAIRO_REGION_OVERLAP_OUT;
+  return cairo_region_contains_rectangle (snapshot->state->clip_region, &offset_rect) == CAIRO_REGION_OVERLAP_OUT;
 }
 
 /**
index f03cef7a31c3969ee5cd65c1df0b34d479b153c9..0b691c3486ab2d473bdfc1833157574b1d288a88 100644 (file)
@@ -90,8 +90,8 @@ void            gtk_snapshot_translate_2d               (GtkSnapshot
                                                          int                     y);
 GDK_AVAILABLE_IN_3_90
 void            gtk_snapshot_get_offset                 (GtkSnapshot            *snapshot,
-                                                         double                 *x,
-                                                         double                 *y);
+                                                         int                    *x,
+                                                         int                    *y);
 
 GDK_AVAILABLE_IN_3_90
 void            gtk_snapshot_append_node                (GtkSnapshot            *snapshot,
@@ -116,7 +116,7 @@ void            gtk_snapshot_append_color_node          (GtkSnapshot
 
 GDK_AVAILABLE_IN_3_90
 gboolean        gtk_snapshot_clips_rect                 (GtkSnapshot            *snapshot,
-                                                         const graphene_rect_t  *bounds);
+                                                         const cairo_rectangle_int_t  *bounds);
 
 GDK_AVAILABLE_IN_3_90
 void            gtk_snapshot_render_background          (GtkSnapshot            *snapshot,
index 2384a8b55f7d0df8c27076556c006b72ce27e532..91d1b66ef6a9ac53e556fc85a7c2151e4d7fb44d 100644 (file)
@@ -37,8 +37,8 @@ struct _GtkSnapshotState {
   GPtrArray             *nodes;
 
   cairo_region_t        *clip_region;
-  double                 translate_x;
-  double                 translate_y;
+  int                    translate_x;
+  int                    translate_y;
 
   GtkSnapshotCollectFunc collect_func;
   union {
index fc5edbc8890c8baedef05036acaa9a8aaa9537cc..2f93d63413830ccf54de893cda0039cfc4fdd9cf 100644 (file)
@@ -15591,15 +15591,17 @@ gtk_widget_snapshot (GtkWidget   *widget,
   GtkCssValue *filter_value;
   RenderMode mode;
   double opacity;
+  cairo_rectangle_int_t offset_clip;
 
   if (_gtk_widget_get_alloc_needed (widget))
     return;
 
   priv = widget->priv;
-  graphene_rect_init (&bounds, priv->clip.x - priv->allocation.x,
-                      priv->clip.y - priv->allocation.y,
-                      priv->clip.width, priv->clip.height);
-  if (gtk_snapshot_clips_rect (snapshot, &bounds))
+  offset_clip = priv->clip;
+  offset_clip.x -= priv->allocation.x;
+  offset_clip.y -= priv->allocation.y;
+
+  if (gtk_snapshot_clips_rect (snapshot, &offset_clip))
     return;
 
   if (_gtk_widget_is_toplevel (widget))
@@ -15620,6 +15622,12 @@ gtk_widget_snapshot (GtkWidget   *widget,
   filter_value = _gtk_style_context_peek_property (_gtk_widget_get_style_context (widget), GTK_CSS_PROPERTY_FILTER);
   gtk_css_filter_value_push_snapshot (filter_value, snapshot);
 
+  graphene_rect_init (&bounds,
+                      offset_clip.x,
+                      offset_clip.y,
+                      offset_clip.width,
+                      offset_clip.height);
+
   if (mode == RENDER_DRAW)
     {
       cairo_t *cr;